digit		[0-9]
letter		[A-Za-z]
alphanum	({letter}|{digit})

%{
	#include <stdio.h>
	#include "y.tab.h"
	#include "../model/datatypes.h"
	#include "../model/limits.h"
	#include "../model/internal_kb.h"
	#define YYSTYPE Expression
	extern YYSTYPE yylval;
	#define OTHER_TOKEN -1
	void yyerror(char *);
	int last_token = OTHER_TOKEN;

	// for keeping track of whether we are currently parsing a role composition
	char parsing_role_inclusion;
	char parsing_transitive_role;

	enum concept_description_type  parse_stack[MAX_CONJ_EXISTS_ALTERNATION];
	int parse_stack_top;

%}

%%

\n			{ ++yylineno; }

			/* skip whitespace */
[ \t]			;

			/* skip comments */
"//".*\n		;

			/* full IRI, not very precise */
"<http://"({alphanum}|\.|\/|\?|-|~)+"#"({alphanum}|-|_|\.)+">" {
			 if (parsing_role_inclusion || parsing_transitive_role || last_token == OBJECTSOMEVALUESFROM) {
		 	 	// printf("role:%s\n",yytext);
			 	yylval.role = create_atomic_role(yytext);
				last_token = OTHER_TOKEN;
			 	return FULLIRI; 
			 }
			 // in all other cases, the IRI is in a concept description
		 	 // printf("concept:%s\n",yytext);
		 	 yylval.concept = create_atomic_concept(yytext);
			 return FULLIRI; 
			}

"<http://"({alphanum}|\.|\/|\?|\*|-|_|~)+[#]?">"	{
				return BASEIRI; 
			}

			/* parantheses, etc ... */
	/* [()=]			{ return *yytext; } */
[():<>=]			{ return *yytext; }

			/* ontology */
	/* Prefix			{ return PREFIX; } */
Prefix.*	; /* skip it */

Ontology 		{ return ONTOLOGY; }
Import			{ return IMPORT; }

			/* skip declarations, irrelevant for reasoning */
Declaration.*		;	// { return DECLARATION; }

AnnotationAssertion.*	;		/* skip annotation assertions */

Annotation.*		;		/* skip ontology annotations */

EntityAnnotation.*	;		

Label.*			;		

DisjointClasses.*			;		

TransitiveObjectProperty	{ 
			 parsing_transitive_role = 1;
			 return TRANSITIVE_OBJECT_PROPERTY; 
			}

Class			{ return CLASS;}

EquivalentClasses	{ return EQUIVALENTCLASSES; }

SubClassOf		{ return SUBCLASSOF; }

ObjectIntersectionOf	{ 
			 // parse_stack[parse_stack_top++] = CONJUNCTION;
			 return OBJECTINTERSECTIONOF; 
			}

ObjectSomeValuesFrom	{ 
			 // parse_stack[parse_stack_top++] = EXISTENTIAL_RESTRICTION;
			 last_token = OBJECTSOMEVALUESFROM;
			 return OBJECTSOMEVALUESFROM;
			}

ObjectProperty		{ return OBJECTPROPERTY; }

SubObjectPropertyChain	{ 
			 return OBJECTPROPERTYCHAIN; 
			}

SubObjectPropertyOf	{
			 parsing_role_inclusion = 1;
			 return SUBOBJECTPROPERTYOF; 
			}

	/* {alphanum}+	{ return IDENTIFIER; } */
[0-9A-Za-z_]+	{ return IDENTIFIER; }

	/*
[0-9A-Za-z:<>\/\.#-_]+	{ 
			 if (parsing_role_inclusion || last_token == OBJECTSOMEVALUESFROM) {
				printf("role:%s\n",yytext);
			 	yylval.role = create_atomic_role(yytext);
				last_token = OTHER_TOKEN;
			 	return IDENTIFIER; 
			 }
			 // in all other cases, the IRI is in a concept description
		 	 printf("concept:%s\n",yytext);
		 	 yylval.concept = create_atomic_concept(yytext);
			 return IDENTIFIER; 
			}
	*/


			/* anything else is an error */
.			{ ECHO ; yyerror("unexpected character"); }

%%

int yywrap(void) {
	return 1;
}
